var ReportJira = function () {

    this.$jiraConditionTable = $('#jira_condition_table');
    this.$jiraSearchRecordBtn = $('#jira_search_record_btn');
    this.$jiraSearchBtn = $('#jira_search_btn');
    this.$jiraChartRenderBtn = $('#jira_chart_render_btn');
    this.$jiraChartSaveBtn = $('#jira_chart_save_btn');
    this.$jiraChartAddBtn = $('#jira_chart_add_btn');
    this.$jiraChartClearBtn = $('#jira_chart_clear_btn');
    this.$jiraChartControl = $('.jira-chart-control');
    this.$jiraExcelExportBtn = $('#jira_excel_export_btn');
    this.$jiraExcelExportForm = $('#jira_excel_export_form');
    this.$jiraTableColumn = $('#jira_table_column');
    this.$addChartRowBtn = $('#add_chart_row_btn');

    this.$grid_selector = $("#jira_grid_table");
    this.pager_selector = "#jira_grid_pager";

    this.URL = {
        REPORT_CONDITION_TYPE: '/report/design/jira/condition/type/get',
        RECORD_GET_ALL: '/report/record/get/all/mine',
        REPORT_RECORD_ADD: '/report/record/add',
        RENDER_CHART: '/jira/render/chart',
        SUB_GET: '/jira/issue/sub',
        GET_ALL_TYPE: '/jira/issue/type/name',
        GET_ALL_STATUS: '/jira/issue/status/name',
        PROJECT_LIST: '/jira/project/page',
        USER_LIST: '/jira/user/page',
        SPRINT_LIST: '/jira/sprint/{{projectName}}',
        PROJECT_VERSION_LIST: '/jira/project/version/{{projectName}}'
    };


    var self = this;
    this.colModel = [
        {layout: false, name: 'id', label: 'ID', hidden: true, key: true},
        {
            layout: false,
            name: 'hasSub',
            label: '关联ISSUE',
            fixed: true,
            width: 80,
            formatter: function (cellValue) {
                return cellValue ? '<span style="color: red;">有</span>' : '无';
            }
        },
        {
            name: 'keyword', label: 'ISSUE', formatter: function (cellValue, row, rowObj) {
                return '<a target="_blank" href="' + rowObj.keywordUrl + '">' + cellValue + '</a>';
            }
        },
        {layout: false, name: 'keywordUrl', label: "jira访问url", hidden: true},
        {name: 'statusName', label: '状态'},
        {name: 'typeName', label: '类型'},
        {name: 'priorityName', label: '等级'},
        {name: 'summary', label: '主题'},
        {name: 'projectName', label: '项目'},
        {name: 'assigneeName', label: '经办人'},
        {name: 'reporterName', label: '汇报人'},
        {name: 'created', label: '创建时间'},
        {name: 'updated', label: '最后更新时间'}
    ];
    this.options = {
        datatype: 'local',
        mtype: 'post',
        moduleKey: 'jira',
        pager: this.pager_selector,
        sortname: 'keyword',
        colModel: this.colModel,
        subGrid: true,
        subGridRowExpanded: function (subGridId, rowId) {
            var $table = $(self.subTableTemplate);

            $.get(self.URL.SUB_GET, {issueId: rowId})
                .done(function (res) {
                    if (res.success) {
                        if (res.data.length === 0) {
                            $table = "没有数据";
                        } else {
                            for (var idx in res.data) {
                                $table.find('tbody').append(self.subRowTemplate(res.data[idx]))
                            }
                        }
                        $("#" + subGridId).html($table);
                    } else {
                        $.xumf.gritter(res);
                    }
                });
        },
        navbarDefaultIcon: {
            add: false,
            edit: false,
            view: false,
            del: false
        }
    };

    this.condition = {
        1: '>',
        2: '<',
        3: '=',
        4: '>=',
        5: '<=',
        6: '!=',
        7: 'in',
        8: 'notIn',
        9: 'betweenAnd',
        10: 'like'
    };
    this.typeData = [
        {id: 'project', text: '项目'},
        {id: 'card', text: 'ISSUE'},
        {id: 'status_name', text: '状态'},
        {id: 'type_name', text: '类型'},
        {id: 'assignee_name', text: '经办人'},
        {id: 'reporter_name', text: '汇报人'},
        {id: 'created', text: '创建时间'},
        {id: 'updated', text: '最后更新时间'},
        {id: 'sprint_name', text: 'sprint名'},
        {id: 'custom_field', text: '自定义字段'},
        {id: 'fix_version', text: 'FixVersion'}
    ];
    this.conditionType = [];
    this.trData = [];
    this.chartData = {dateType: 1, chartTrData: [], layout: 'keyword'};

    this.conditionLiTemplate = _.template(
        '<tr>\
            <td style="padding-top: 15px;" width="200">\
                <label class="radio-inline">\
                    <input {{relation_and}} type="radio" value="1" name="{{radioId}}-relation" class="ace">\
                    <span class="lbl"> AND</span>\
                </label>\
                <label class="radio-inline">\
                    <input {{relation_or}} type="radio" value="0" name="{{radioId}}-relation" class="ace">\
                    <span class="lbl"> OR</span>\
                </label>\
            </td>\
            <td width="200px">\
                {{typeComponent}}\
            </td>\
            <td width="100px">\
                <select name="condition" autocomplete="off" class="form-control">\
                    <option {{condition_selected_1}} value="1">></option>\
                    <option {{condition_selected_2}} value="2"><</option>\
                    <option {{condition_selected_3}} value="3">=</option>\
                    <option {{condition_selected_4}} value="4">>=</option>\
                    <option {{condition_selected_5}} value="5"><=</option>\
                    <option {{condition_selected_6}} value="6">!=</option>\
                    <option {{condition_selected_7}} value="7">in</option>\
                    <option {{condition_selected_8}} value="8">notIn</option>\
                    <option {{condition_selected_9}} value="9">betweenAnd</option>\
                    <option {{condition_selected_10}} value="10">like</option>\
                </select>\
            </td>\
            <td id="condition_content">\
            </td>\
            <td width="55px">\
                <button data-condition-type="{{type}}" class="btn btn-danger btn-sm" type="button"><i class="glyphicon glyphicon-minus"></i></button>\
            </td>\
        </tr>');

    this.chartRowTemplate = _.template('<tr align="center">\
                                            <td style="line-height: 38px;">\
                                                维度 \
                                            </td>\
                                            <td>\
                                                <select name="dimension" multiple="multiple" title="" autocomplete="off">{{dimensionOption}}</select>\
                                            </td>\
                                            <td style="line-height: 38px;">\
                                                统计数据（y轴）\
                                            </td>\
                                            <td>\
                                                <select name="statistics" title="" autocomplete="off">{{statisticsOption}}</select>\
                                            </td>\
                                        </tr>');

    this.saveTemplate = _.template('<form style="padding: 12px;" class="form">\
                        <input class="form-control" name="fcrId" type="hidden">\
                        <div class="form-group">\
                            <label>名称</label>\
                            <input autocomplete="off" class="form-control" name="name">\
                        </div>\
                        <div class="form-group">\
                            <label >已有记录</label>\
                            <select class="form-control"  name="record">\
                            {{option}}\
                            </select>\
                        </div>\
                        </form>');

    this.recordTemplate = _.template('<form style="padding: 12px;" class="form">\
                        <div class="form-group">\
                            <label >已有记录</label>\
                            <select class="form-control"  name="record">\
                            {{option}}\
                            </select>\
                        </div>\
                        </form>');

    this.subTableTemplate = "<table class='table table-bordered'>\
                                <thead>\
                                    <tr><th>ISSUE</th><th>主题</th><th>状态</th><th>解决情况</th><th>关联类型</th></tr>\
                                </thead>\
                                <tbody></tbody>\
                            </table>";

    this.subRowTemplate = _.template(
        '<tr style="background-color: white;">\
            <td><a target="_blank" href="{{keywordUrl}}">{{keyword}}</a></td>\
            <td>{{summary}}</td>\
            <td>{{statusName}}</td>\
            <td>{{handleResult}}</td>\
            <td>{{linkType}}</td>\
        </tr>'
    );

};

ReportJira.prototype = {
    init: function () {
        this.$grid_selector
            .xumf_jqGird(this.options);

        this.$jiraChartControl.hide();

        this.initSelectedControl();
        this.bindClickEvent();
        this.bindChangeEvent();

        $('[data-rel=popover]').popover({container:'body'});
        this.addChartRow({dimensionList: [], statistics: {name: "keyword", label: "ISSUE"}});
    },
    setContent: function (type, $target, text) {
        text = text ? text : '';
        var self = this;
        var $closest = $target.closest('tr');
        var $content = $closest.find('#condition_content');
        if (type === 'project') {
            self.createPageSelect(self.URL.PROJECT_LIST, $closest, $content, text.split(','))
        } else if (type === 'assignee_name' || type === 'reporter_name') {
            self.createPageSelect(self.URL.USER_LIST, $closest, $content, text.split(','))
        } else if (type === 'type_name') {
            self.createNormalSelect(self.URL.GET_ALL_TYPE, $closest, $content, text.split(','));
        } else if (type === 'status_name') {
            self.createNormalSelect(self.URL.GET_ALL_STATUS, $closest, $content, text.split(','));
        } else if (type === 'fix_version' || type === 'sprint_name') {
            var value = _.chain(self.trData)
                .filter(function (o) {
                    return o.type === 'project';
                }).map(function (o) {
                    return o.text
                }).first().value();
            var projectName = value ? value : '';
            var url = type === 'fix_version' ? self.URL.PROJECT_VERSION_LIST : self.URL.SPRINT_LIST;
            self.createNormalSelect(_.template(url)({projectName: projectName}), $closest, $content, text.split(','));
        }
        else {
            $closest.find('select[name=condition]').attr('disabled', false).trigger('change');
            $content.html(_.template('<input value="{{text}}" name="text" class="form-control" autocomplete="off">')({text: text}));
        }
    },
    createNormalSelect: function (url, $closest, $content, ary) {
        var selectedAry = _.map(ary, function (o) {
            return {selected: true, value: o};
        });
        $closest.find('select[name=condition]').val(7).attr('disabled', true).trigger('change');
        $content.html('<select multiple="multiple" name="contentSelect" class="form-control" style="width: 200px;"></select>').find('select').xumf_select({
            url: url,
            select: selectedAry
        }).on('xumf.select.success', function () {
            $(this).multiselect({
                enableFiltering: true,
                buttonWidth: '301px',
                filterPlaceholder: '搜索字母区分大小写',
                selectAllText: '全选',
                allSelectedText: '全选',
                nonSelectedText: '未选',
                nSelectedText: '项 已选择 '
            });
        });
    },
    createPageSelect: function (url, $closest, $content, ary) {

        $closest.find('select[name=condition]').val(7).attr('disabled', true).trigger('change');
        var nAry = _.map(ary, function (o) {
            return {
                label: o,
                value: o,
                selected: true
            }
        });
        $content.html('<select multiple="multiple" name="contentSelect" class="form-control" style="width: 300px;"></select>').find('select')
            .xumf_select({data: nAry})
            .select2({
                language: "zh-CN",
                ajax: {
                    url: url,
                    data: function (params) {
                        return {
                            searchString: params.term,
                            page: params.page || 1,
                            rows: 20
                        };
                    },
                    processResults: function (res, params) {
                        params.page = params.page || 1;
                        var rows = _.map(res.rows, function (o) {
                            return {
                                id: o.label,
                                text: o.label
                            }
                        });
                        return {
                            results: rows,
                            pagination: {
                                more: res.page < res.total
                            }
                        };
                    }
                }
            });

    },
    createSelect: function (type) {
        var $el = $('<select name="typeSelect" class="form-control" style="width: 200px;"></select>');
        for (var i = 0; i < this.typeData.length; i++) {
            var item = this.typeData[i];
            $el.append(_.template('<option {{selected}} {{disabled}} value="{{id}}">{{text}}</option>')({
                selected: type === item.id ? 'selected' : '',
                disabled: item.disabled ? 'disabled' : '',
                id: item.id,
                text: item.text
            }));
        }
        return $el[0].outerHTML;
    },
    searchRecordAction: function () {

        var self = this;
        $.xumf.ajaxAndLoading({
            type: 'get',
            url: this.URL.RECORD_GET_ALL
        }).done(function (res) {
            if (!res.success) {
                $.xumf.gritter(res);
                return;
            }
            var optionTemplate = "";
            res.data.forEach(function (item) {
                optionTemplate = optionTemplate + "<option value='" + item.value + "'>" + item.label + "</option>";
            });
            layer.open({
                title: '保存',
                area: ['300px', '180px'],
                content: self.recordTemplate({option: optionTemplate}),
                yes: function (index, layero) {
                    var $record = $(layero).find('select[name="record"]');
                    $.xumf.ajaxAndLoading({
                        type: 'get',
                        url: '/report/record/get',
                        data: {id: $record.val()}
                    }).done(function (res) {
                        $.xumf.gritter(res);
                        if (res.success) {
                            layer.close(index);
                        }
                        self.renderCondition(JSON.parse(res.data.tableCondition));
                        self.renderChartCondition(JSON.parse(res.data.chartCondition));
                    });
                }
            })
        });
    },
    /**
     * 保存操作
     */
    saveAction: function () {

        var self = this;
        $.xumf.ajaxAndLoading({
            type: 'get',
            url: this.URL.RECORD_GET_ALL
        }).done(function (res) {
            if (!res.success) {
                $.xumf.gritter(res);
                return;
            }
            var optionTemplate = "<option value='0'>请选择</option>";
            res.data.forEach(function (item) {
                optionTemplate = optionTemplate + "<option value='" + item.value + "'>" + item.label + "</option>";
            });

            layer.open({
                title: '保存',
                area: ['300px', '280px'],
                content: self.saveTemplate({option: optionTemplate}),
                yes: function (index, layero) {
                    var name = $(layero).find('input[name="name"]').val();
                    var fcrId = $(layero).find('input[name="fcrId"]').val();
                    if ('' === name.trim()) {
                        $.xumf.gritterError('名称不能为空！');
                        return;
                    }
                    $.xumf.ajaxAndLoading({
                        url: self.URL.REPORT_RECORD_ADD,
                        data: {
                            fcrId: fcrId,
                            name: name,
                            tableCondition: JSON.stringify(self.trData),
                            chartCondition: JSON.stringify(self.chartData)
                        }
                    }).done(function (res) {
                        $.xumf.gritter(res);
                        if (res.success) {
                            layer.close(index);
                        }
                    });
                },
                success: function (layero, index) {
                    var $name = $(layero).find('input[name="name"]');
                    var $fcrId = $(layero).find('input[name="fcrId"]');
                    var $record = $(layero).find('select[name="record"]');
                    $record.on('change', function (event) {
                        $name.val($(event.target).find('option:selected').text());
                        $fcrId.val($(event.target).val());
                        event.preventDefault();
                    });
                    $name.on('change', function (event) {
                        $record.find('option').each(function (index, item) {
                            if ($(item).text() === $(event.target).val()) {
                                $fcrId.val($(item).val());
                                $(item).attr('selected', true);
                                return false;
                            } else {
                                $(item).attr('selected', false);
                            }
                        });
                        $fcrId.val('0');
                        event.preventDefault();
                    })
                }
            })
        });

    },
    /**
     * 搜索操作
     */
    searchAction: function () {
        this.$jiraChartControl.show();
        this.$grid_selector.setGridParam({
            page: 1,
            datatype: 'json',
            postData: {searchString: JSON.stringify(this.trData)}
        }).trigger('reloadGrid');
    },
    /**
     * 渲染统计图
     */
    renderChart: function () {

        var params = {
            trData: this.trData,
            chartData: this.chartData
        };
        var reportJiraChart;

        var resizeChart = function (layero) {
            var width = $(layero).find('.layui-layer-content').width();
            var height = $(layero).find('.layui-layer-content').height();
            $(layero).find('#report_jira_chart_content').css({width: width, height: height});
            reportJiraChart.resize();
        };

        var self = this;
        layer.open({
            title: '统计图',
            area: ['800px', '550px'],
            closeBtn: 1,
            fixed: true,
            btn: null,
            content: '<div style="width: 800px; height: 500px;" id="report_jira_chart_content"></div>',
            full: function (layero) {
                resizeChart(layero);
            },
            restore: function (layero) {
                resizeChart(layero);
            },
            success: function (layero, index) {
                reportJiraChart = echarts.init($(layero).find('#report_jira_chart_content')[0]);
                reportJiraChart.showLoading();
                $.ajax({
                    contentType: "application/json",
                    url: self.URL.RENDER_CHART,
                    data: JSON.stringify(params)
                }).done(function (res) {
                    reportJiraChart.hideLoading();
                    if (!res.success) {
                        $.xumf.gritter(res);
                        layer.close(index);
                        return;
                    }
                    if (JSON.stringify(res.data) === "{}") {
                        $.xumf.gritterError("请正确配置维度，布局，统计");
                        layer.close(index);
                        return;
                    }
                    // 指定图表的配置项和数据
                    var option = {
                        toolbox: {
                            show: true,
                            dataZoom: {
                                yAxisIndex: 'none'
                            },
                            feature: {
                                restore: {show: true},
                                magicType: {
                                    show: true,
                                    type: ['line', 'bar']
                                },
                                saveAsImage: {
                                    show: true
                                }
                            }
                        },
                        grid: {
                            right: '15%',
                            bottom:'15%'
                        },
                        legend: {},
                        tooltip: {
                            trigger: 'axis',
                            axisPointer: {
                                type: 'cross'
                            }
                        },
                        dataset: res.data.dataset,
                        // 声明一个 X 轴，类目轴（category）。默认情况下，类目轴对应到 dataset 第一列。
                        xAxis: {type: 'category', axisLabel: {interval: 0, rotate: 40}},
                        // 声明一个 Y 轴，数值轴。
                        yAxis: res.data.yAxis,
                        // 声明多个 bar 系列，默认情况下，每个系列会自动对应到 dataset 的每一列。
                        series: res.data.series
                    };
                    reportJiraChart.setOption(option)
                }).complete(function () {
                    reportJiraChart.hideLoading();
                }).error(function () {
                    reportJiraChart.hideLoading();
                });
            },
            end: function () {
                if (reportJiraChart !== null || reportJiraChart !== undefined) {
                    reportJiraChart.clear();
                }
            }
        });
    },
    /**
     * 渲染表格条件
     * @param data
     */
    renderCondition: function (data) {

        var self = this;
        self.clearAllTableCondition();
        data.forEach(function (item) {
            self.addRow(item)
        });
    },
    /**
     * 渲染统计图条件
     * @param data
     */
    renderChartCondition: function (data) {
        var self = this;
        this.chartData = {dateType: 1, chartTrData: [], layout: 'keyword'};
        this.$jiraTableColumn.find('table>tbody').empty();
        this.$jiraTableColumn.find('select[name="layout"]').multiselect('select', data.layout, false).multiselect('refresh');
        this.chartData.layout = data.layout;
        this.$jiraTableColumn.find('label>input[name="dateType"]').each(function (index, item) {
            if ($(item).val() === data.dateType) {
                $(item).prop('checked', true);
            }
        });
        this.chartData.dateType = data.dateType;
        data.chartTrData.forEach(function (item) {
            self.addChartRow(item);
        });
    },
    /**
     * 删除一行
     * @param rowNumber 行数
     */
    removeRow: function (rowNumber) {

        this.trData.splice(rowNumber, 1);
        this.$jiraConditionTable.children('tbody').children('tr:eq(' + rowNumber + ')')
            .fadeOut('fast', function () {
                $(this).remove();
            });
    },
    /**
     * 添加一行
     * @param data
     */
    addRow: function (data) {
        this.trData.push(data);
        var params = {
            radioId: new Date().getTime(),
            relation_and: data.relationType ? 'checked' : '',
            relation_or: !data.relationType ? 'checked' : '',
            typeComponent: this.createSelect(data.type),
            text: data.text,
            type: data.type
        };
        for (var i = 1; i <= 10; i++) {
            params['condition_selected_' + i] = parseInt(data.condition) === i ? 'selected' : '';
        }
        var self = this;
        var $conditionLiTemplate = $(this.conditionLiTemplate(params));
        this.$jiraConditionTable.children('tbody').append($conditionLiTemplate).children('tr:last').fadeIn('fast', function () {
            self.setContent(data.type, $(this), data.text);
        });

    },
    /**
     * 添加统计图数据一行
     * @param data
     */
    addChartRow: function (data) {
        this.chartData.chartTrData.push(data);
        var column = _.filter(this.colModel, function (o) {
            return o.layout === undefined || o.layout === true;
        });
        var dimensionOptionTemplate = "";
        column.forEach(function (item) {
            dimensionOptionTemplate = dimensionOptionTemplate + _.template("<option {{selected}} value='{{name}}'>{{label}}</option>")
            ({
                name: item.name,
                label: item.label,
                selected: _.contains(data.dimensionList, item.name) ? 'selected' : ''
            });
        });
        var statisticsOptionTemplate = "";
        column.forEach(function (item) {
            statisticsOptionTemplate = statisticsOptionTemplate + _.template("<option {{selected}} value='{{name}}'>{{label}}</option>")
            ({
                name: item.name,
                label: item.label,
                selected: data.statistics.name === item.name ? 'selected' : ''
            });
        });
        var chartRowTemplate = this.chartRowTemplate({
            dimensionOption: dimensionOptionTemplate,
            statisticsOption: statisticsOptionTemplate
        });
        this.$jiraTableColumn.find('table>tbody').append(chartRowTemplate);
        this.initSelectedControl();
    },
    /**
     * 删除一行
     * @param rowNumber 行数
     */
    removeChartRow: function (rowNumber) {

        this.chartData.chartTrData.splice(rowNumber, 1);
        this.$jiraTableColumn.find('table>tbody').children('tr:eq(' + rowNumber + ')')
            .fadeOut('fast', function () {
                $(this).remove();
            });
    },
    initSelectedControl: function () {

        var self = this;
        this.$jiraTableColumn.find('select[name="statistics"]').multiselect({
            buttonWidth: '201px',
            nonSelectedText: '未选'
        });
        this.$jiraTableColumn.find('select[name="dimension"]').multiselect({
            buttonWidth: '201px',
            allSelectedText: '全选',
            nonSelectedText: '未选'
        });
        var $layoutSelect = this.$jiraTableColumn.find('select[name="layout"]');
        _.filter(this.colModel, function (o) {
            return o.layout === undefined || o.layout === true;
        }).forEach(function (item) {
            $layoutSelect.append(_.template('<option value="{{name}}">{{label}}</option>')(item));
        });
        $layoutSelect.multiselect({
            buttonWidth: '201px',
            nonSelectedText: '未选',
            onChange: function (element) {
                self.chartData.layout = element.val();
            }
        });
    },
    /**
     * 绑定点击事件
     */
    bindClickEvent: function () {

        var self = this;
        this.$jiraConditionTable.delegate('tbody>tr>td>button', 'click', function (event) {
            var $tr = $(event.currentTarget).closest('tr');
            self.removeRow($tr.index());
        });
        this.$jiraTableColumn.delegate('table>tbody>tr>td>button', 'click', function (event) {
            var index = $(event.currentTarget).closest('tr').index();
            self.removeChartRow(index);
        });
        this.$jiraSearchBtn.on('click', function (event) {
            event.preventDefault();
            self.searchAction();
        });
        this.$jiraChartAddBtn.on('click', function (event) {
            event.preventDefault();
            self.addRow({type: 'project', condition: 3, text: '', relationType: true});
        });
        this.$jiraChartClearBtn.on('click', function (event) {
            event.preventDefault();
            self.clearAllTableCondition();
        });
        this.$jiraChartRenderBtn.on('click', function (event) {
            event.preventDefault();
            self.renderChart();
        });
        this.$jiraExcelExportBtn.on('click', function (event) {
            event.preventDefault();
            self.$jiraExcelExportForm.find('input[name="jiraSearchDTOListStr"]').val(JSON.stringify(self.trData));
            self.$jiraExcelExportForm.submit();
        });
        this.$jiraChartSaveBtn.on('click', function (event) {
            event.preventDefault();
            self.saveAction();
        });
        this.$jiraSearchRecordBtn.on('click', function (event) {
            event.preventDefault();
            self.searchRecordAction();
        });
        this.$addChartRowBtn.on('click', function (event) {
            event.preventDefault();
            self.addChartRow({dimensionList: [], statistics: {name: "keyword", label: "ISSUE"}});
        });
    },
    /**
     * 清空所有表格条件（不包括统计图的条件）
     */
    clearAllTableCondition: function () {
        this.trData = [];
        this.$jiraConditionTable.children('tbody').empty();
    },
    /**
     * 绑定change事件
     */
    bindChangeEvent: function () {

        var self = this;
        // 事件绑定
        this.$jiraConditionTable.delegate('tbody>tr>td>input[name="text"]', 'change', function (event) {
            var index = $(event.currentTarget).closest('tr').index();
            self.trData[index].text = $(event.currentTarget).val();
        });
        this.$jiraConditionTable.delegate('tbody>tr>td>select[name="contentSelect"]', 'change', function (event) {
            var $target = $(event.currentTarget);
            var index = $target.closest('tr').index();
            var currentVal = $target.val();
            if ($target.attr('multiple') === "multiple") {
                currentVal = $.isArray(currentVal) ? currentVal.join(',') : currentVal;
            } else {
                currentVal = $target.val();
            }
            self.trData[index].text = currentVal;
        });
        this.$jiraConditionTable.delegate('tbody>tr>td>select[name="condition"]', 'change', function (event) {
            var index = $(event.currentTarget).closest('tr').index();
            self.trData[index].condition = $(event.currentTarget).val();
        });
        this.$jiraConditionTable.delegate('tbody>tr>td>select[name="typeSelect"]', 'change', function (event) {
            var $target = $(event.currentTarget);
            var index = $target.closest('tr').index();
            var val = $target.val();
            self.trData[index].type = val;
            self.setContent(val, $target)
        });
        this.$jiraConditionTable.delegate('tbody>tr>td>label>input[type="radio"]', 'change', function (event) {
            var $target = $(event.currentTarget);
            var index = $target.closest('tr').index();
            self.trData[index].relationType = parseInt($target.val()) > 0;
        });
        this.$jiraConditionTable.delegate('tbody>tr>td>input[name="text"]', 'change', function (event) {
            var index = $(event.currentTarget).closest('tr').index();
            self.trData[index].text = $(event.currentTarget).val();
        });

        this.$jiraTableColumn.delegate('select[name="statistics"]', 'change', function (event) {
            var $target = $(event.currentTarget);
            var index = $target.closest('tr').index();
            self.chartData.chartTrData[index].statistics = {
                name: $target.val(),
                label: $target.find('option:selected').text()
            };
        });
        this.$jiraTableColumn.delegate('select[name="dimension"]', 'change', function (event) {
            var index = $(event.currentTarget).closest('tr').index();
            self.chartData.chartTrData[index].dimensionList = $(event.currentTarget).val() || [];
        });
        this.$jiraTableColumn.delegate('label>input[name="dateType"]', 'change', function (event) {
            var $target = $(event.currentTarget);
            if ($target.prop('checked')) {
                self.chartData.dateType = $target.val();
            }
        });
    }
};



